%%%-------------------------------------------------------------------
%% @doc hprose public API
%% @end
%%%-------------------------------------------------------------------

-module(hprose_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).

%%====================================================================
%% API
%%====================================================================

start(_StartType, StartArgs) ->
  Ret = hprose_sup:start_link(),
  PORT = proplists:get_value(port, StartArgs, 8080),
  Dispatch = cowboy_router:compile([{'_', [{"/", hprose_http_handler, StartArgs}]}]),
  {ok, _} = cowboy:start_clear(http, [{port, PORT}], #{
    env => #{dispatch => Dispatch}
  }),
  Ret.

%%--------------------------------------------------------------------
stop(_State) ->
  ok.

%%====================================================================
%% Internal functions
%%====================================================================
